<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Lines Template</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html">
<img src="../docs-assets/Inform.png" height=72">
</a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../indocn.html">indoc</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=18> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="../../../inweb/index.html">inweb</a></li>
<li><a href="../../../intest/index.html">intest</a></li>

</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Lines Template' generated by Inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../extensions.html">Kits</a></li><li><a href="index.html">DialogueKit</a></li><li><b>Lines Template</b></li></ul></div>
<p class="purpose">Runtime support for dialogue lines.</p>

<ul class="toc"><li><a href="S-lns.html#SP1">&#167;1. Runtime representation</a></li><li><a href="S-lns.html#SP2">&#167;2. Extracting line data</a></li><li><a href="S-lns.html#SP3">&#167;3. Determining the speakers</a></li><li><a href="S-lns.html#SP4">&#167;4. Scoring possible speakers</a></li><li><a href="S-lns.html#SP5">&#167;5. Performing a line</a></li><li><a href="S-lns.html#SP6">&#167;6. Running the performing activity</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Runtime representation. </b>Values representing lines are enumerated from 1 to <span class="extract"><span class="extract-syntax">NO_DIALOGUE_LINES</span></span>. Lines
have certain properties stored by Inform just as it would for any other
enumerated kind, and which this kit deals with by calls to <span class="extract"><span class="extract-syntax">GProperty</span></span> and
<span class="extract"><span class="extract-syntax">WriteGProperty</span></span>: in particular, <span class="extract"><span class="extract-syntax">performed</span></span> and <span class="extract"><span class="extract-syntax">recurring</span></span>.
</p>

<p class="commentary">In addition, though, the compiler (or more accurately the linker) generates
a table called <span class="extract"><span class="extract-syntax">TableOfDialogueLines</span></span>. If <span class="extract"><span class="extract-syntax">dl</span></span> is an enumerated value then
<span class="extract"><span class="extract-syntax">TableOfDialogueLines--&gt;dl</span></span> is the address of the metadata table for <span class="extract"><span class="extract-syntax">dl</span></span>.
(And <span class="extract"><span class="extract-syntax">TableOfDialogueLines--&gt;0</span></span> is set to <span class="extract"><span class="extract-syntax">NO_DIALOGUE_LINES</span></span>.)
</p>

<p class="commentary">These line data arrays consist of 8 words, as follows:
</p>

<ul class="items"><li>&#9679; <span class="extract"><span class="extract-syntax">AVAILABILITY_DLMETADATA</span></span> is a function to test whether any <span class="extract"><span class="extract-syntax">if</span></span> or <span class="extract"><span class="extract-syntax">unless</span></span>
conditions attached to the line are met; this returns <span class="extract"><span class="extract-syntax">true</span></span> if the line is
available, <span class="extract"><span class="extract-syntax">false</span></span> if not. If the <span class="extract"><span class="extract-syntax">AVAILABILITY_DLMETADATA</span></span> is 0, the line is
always available.
</li><li>&#9679; <span class="extract"><span class="extract-syntax">SPEAKER_DLMETADATA</span></span> is either 0, meaning the line is narration and has no
speaker, or has metaclass <span class="extract"><span class="extract-syntax">Object</span></span>, and is therefore an specific person or
object which speaks, or else has metaclass <span class="extract"><span class="extract-syntax">Routine</span></span>, and is in that case
a function which tests whether a given object meets the requirements. For
example, a line attributed only to <span class="extract"><span class="extract-syntax">A woman in the Ballroom</span></span> would result
in a function here. The special value <span class="extract"><span class="extract-syntax">PLAYER_CONVERSATIONALIST</span></span> can also
be used to mean "the player, whoever that currently is".
</li><li>&#9679; <span class="extract"><span class="extract-syntax">INTERLOCUTOR_DLMETADATA</span></span> is similar, but for the interlocutor, and is
more often 0 &mdash; many lines have no interlocutor. The special value
<span class="extract"><span class="extract-syntax">PLAYER_CONVERSATIONALIST</span></span> can also be used to mean "the player, whoever that
currently is".
</li><li>&#9679; <span class="extract"><span class="extract-syntax">SPEECH_DLMETADATA</span></span> is a <span class="extract"><span class="extract-syntax">text</span></span> value for the content (note: an Inform 7
text value, not an I6 <span class="extract"><span class="extract-syntax">String</span></span> literal). This cannot be 0. The text may well
include substitutions, and the compiled code for those substitutions may
assume it can access the activity variables for "performing something".
</li><li>&#9679; <span class="extract"><span class="extract-syntax">STYLE_DLMETADATA</span></span> is the performance style for the line, and is an
enumerated value of the <span class="extract"><span class="extract-syntax">performance style</span></span> kind. For most lines, this is 1,
since that's the enumerated value for the default "spoken normally". This
cannot be 0.
</li><li>&#9679; <span class="extract"><span class="extract-syntax">MENTIONING_DLMETADATA</span></span> is either 0, meaning that the line raises no
new subject, or has metaclass <span class="extract"><span class="extract-syntax">Object</span></span>, in which case it raises only that
one subject, or has metaclass <span class="extract"><span class="extract-syntax">Routine</span></span>, in which case it is a function which
contains a series of calls to <span class="extract"><span class="extract-syntax">DirectorAddLiveSubjectList</span></span>, one for each of
the at least two subjects mentioned.
</li><li>&#9679; <span class="extract"><span class="extract-syntax">ACTIONS_DLMETADATA</span></span> is either 0, or is a function to carry out any
actions or <span class="extract"><span class="extract-syntax">now</span></span> state-changes which accompany the line. The action function <span class="extract"><span class="extract-syntax">A</span></span>,
if given, is called three times: <span class="extract"><span class="extract-syntax">A(3)</span></span> to perform "after ..." actions, and
returning <span class="extract"><span class="extract-syntax">true</span></span> if they succeed or <span class="extract"><span class="extract-syntax">false</span></span> if they fail; then <span class="extract"><span class="extract-syntax">A(2)</span></span> to
perform any "now ..." business, with no meaningful return value; then <span class="extract"><span class="extract-syntax">A(1)</span></span>
to perform "before ..." actions.
</li><li>&#9679; <span class="extract"><span class="extract-syntax">FLAGS_DLMETADATA</span></span> is currently not very useful, and is a bitmap.
The flag <span class="extract"><span class="extract-syntax">NARRATION_FLAG_DLMETADATA</span></span> is redundant right now, since the speaker
field can just as easily reveal whether or not the line is narration.
</li></ul>
<p class="commentary">All of this must of course match what is compiled in <a href="../runtime-module/5-dli.html" class="internal">Dialogue Line Instances (in runtime)</a>.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">AVAILABILITY_DLMETADATA</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">SPEAKER_DLMETADATA</span><span class="plain-syntax">      = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">INTERLOCUTOR_DLMETADATA</span><span class="plain-syntax"> = </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">SPEECH_DLMETADATA</span><span class="plain-syntax">       = </span><span class="constant-syntax">3</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">STYLE_DLMETADATA</span><span class="plain-syntax">        = </span><span class="constant-syntax">4</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">MENTIONING_DLMETADATA</span><span class="plain-syntax">   = </span><span class="constant-syntax">5</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">ACTIONS_DLMETADATA</span><span class="plain-syntax">      = </span><span class="constant-syntax">6</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">FLAGS_DLMETADATA</span><span class="plain-syntax">        = </span><span class="constant-syntax">7</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">NARRATION_FLAG_DLMETADATA</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">NONVERBAL_FLAG_DLMETADATA</span><span class="plain-syntax"> = </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">PLAYER_CONVERSATIONALIST</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
</pre>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. Extracting line data. </b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorLineContent</span><span class="plain-syntax"> </span><span class="identifier-syntax">dl</span><span class="plain-syntax"> </span><span class="identifier-syntax">text</span><span class="plain-syntax"> </span><span class="identifier-syntax">linedata</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">dl</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">dl</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">NO_DIALOGUE_LINES</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">text</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">linedata</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableOfDialogueLines</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">dl</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">CopyPV</span><span class="plain-syntax">(</span><span class="identifier-syntax">text</span><span class="plain-syntax">, </span><span class="identifier-syntax">linedata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">SPEECH_DLMETADATA</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">text</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorLineNarrated</span><span class="plain-syntax"> </span><span class="identifier-syntax">dl</span><span class="plain-syntax"> </span><span class="identifier-syntax">linedata</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">dl</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">dl</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">NO_DIALOGUE_LINES</span><span class="plain-syntax">)) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">linedata</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableOfDialogueLines</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">dl</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">linedata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">FLAGS_DLMETADATA</span><span class="plain-syntax">) &amp; </span><span class="identifier-syntax">NARRATION_FLAG_DLMETADATA</span><span class="plain-syntax">) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorLineNonverbal</span><span class="plain-syntax"> </span><span class="identifier-syntax">dl</span><span class="plain-syntax"> </span><span class="identifier-syntax">linedata</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">dl</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">dl</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">NO_DIALOGUE_LINES</span><span class="plain-syntax">)) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">linedata</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableOfDialogueLines</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">dl</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">linedata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">FLAGS_DLMETADATA</span><span class="plain-syntax">) &amp; </span><span class="identifier-syntax">NONVERBAL_FLAG_DLMETADATA</span><span class="plain-syntax">) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorLineAvailable</span><span class="plain-syntax"> </span><span class="identifier-syntax">dl</span><span class="plain-syntax"> </span><span class="identifier-syntax">linedata</span><span class="plain-syntax"> </span><span class="identifier-syntax">fn</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">dl</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">dl</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">NO_DIALOGUE_LINES</span><span class="plain-syntax">)) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">linedata</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableOfDialogueLines</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">dl</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">fn</span><span class="plain-syntax"> = </span><span class="identifier-syntax">linedata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">AVAILABILITY_DLMETADATA</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">fn</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">fn</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. Determining the speakers. </b>As noted above, the speaker and interlocutor may not be explicitly determined
in the data given to us, and there are times when we have to go to some trouble
to work out who they are.
</p>

<ul class="items"><li>&#9679; <span class="extract"><span class="extract-syntax">DirectorSelectConverser(val, true, nonverbal)</span></span> works out the speaker meant by
<span class="extract"><span class="extract-syntax">val</span></span>, assuming the line is verbal unless <span class="extract"><span class="extract-syntax">nonverbal</span></span> is set.
</li><li>&#9679; <span class="extract"><span class="extract-syntax">DirectorSelectConverser(val, false, nonverbal)</span></span> works out the interlocutor meant by
<span class="extract"><span class="extract-syntax">val</span></span>, assuming the line is verbal unless <span class="extract"><span class="extract-syntax">nonverbal</span></span> is set.
</li></ul>
<p class="commentary">The algorithm below is not very fast if there are large numbers of objects: on
the other hand, it is run only when a line of dialogue is being delivered, so
it cannot be needed often, and the slowness may not matter. Still, there's scope
to optimise this.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">director_speaker_list</span><span class="plain-syntax">;</span>
<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorSelectConverser</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax"> </span><span class="identifier-syntax">select_speaker</span><span class="plain-syntax"> </span><span class="identifier-syntax">nonverbal</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> </span><span class="identifier-syntax">len</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">best</span><span class="plain-syntax"> </span><span class="identifier-syntax">best_score</span><span class="plain-syntax"> </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> </span><span class="identifier-syntax">x</span><span class="plain-syntax"> </span><span class="identifier-syntax">best_count</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">val</span><span class="plain-syntax"> == </span><span class="identifier-syntax">PLAYER_CONVERSATIONALIST</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">player</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="reserved-syntax">metaclass</span><span class="plain-syntax">(</span><span class="identifier-syntax">val</span><span class="plain-syntax">) == </span><span class="identifier-syntax">Object</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="reserved-syntax">metaclass</span><span class="plain-syntax">(</span><span class="identifier-syntax">val</span><span class="plain-syntax">) == </span><span class="identifier-syntax">Routine</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">director_speaker_list</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">director_speaker_list</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CreatePV</span><span class="plain-syntax">(</span><span class="identifier-syntax">LIST_OF_TY</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WritePVField</span><span class="plain-syntax">(</span><span class="identifier-syntax">director_speaker_list</span><span class="plain-syntax">, </span><span class="identifier-syntax">LIST_ITEM_KOV_F</span><span class="plain-syntax">, </span><span class="identifier-syntax">OBJECT_TY</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">LIST_OF_TY_SetLength</span><span class="plain-syntax">(</span><span class="identifier-syntax">director_speaker_list</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">x</span><span class="plain-syntax"> = </span><span class="identifier-syntax">val</span><span class="plain-syntax">(0);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">x</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">x</span><span class="plain-syntax"> == </span><span class="reserved-syntax">true</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">objectloop</span><span class="plain-syntax"> (</span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">K2_thing</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">player</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">val</span><span class="plain-syntax">(</span><span class="identifier-syntax">speaker</span><span class="plain-syntax">)))</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">LIST_OF_TY_InsertItem</span><span class="plain-syntax">(</span><span class="identifier-syntax">director_speaker_list</span><span class="plain-syntax">, </span><span class="identifier-syntax">speaker</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">len</span><span class="plain-syntax"> = </span><span class="identifier-syntax">LIST_OF_TY_GetLength</span><span class="plain-syntax">(</span><span class="identifier-syntax">director_speaker_list</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">len</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">best</span><span class="plain-syntax"> = -1;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">best_score</span><span class="plain-syntax"> = -1;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">best_count</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">len</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> = </span><span class="identifier-syntax">LIST_OF_TY_GetItem</span><span class="plain-syntax">(</span><span class="identifier-syntax">director_speaker_list</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">, </span><span class="identifier-syntax">nonverbal</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> = </span><span class="identifier-syntax">DirectorScoreConverser</span><span class="plain-syntax">(</span><span class="identifier-syntax">speaker</span><span class="plain-syntax">, </span><span class="identifier-syntax">select_speaker</span><span class="plain-syntax">, </span><span class="identifier-syntax">nonverbal</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">best_score</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">best</span><span class="plain-syntax"> = </span><span class="identifier-syntax">speaker</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">best_score</span><span class="plain-syntax"> = </span><span class="identifier-syntax">this_score</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">best_count</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> == </span><span class="identifier-syntax">best_score</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">best_count</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">                </span><span class="comment-syntax">print (name) speaker, " scores ", this_score, "^";</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">best_count</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="string-syntax">"*** impossibly low ***"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="comment-syntax">print best_count, " option(s)^";</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">best_count</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">best</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">x</span><span class="plain-syntax"> = </span><span class="reserved-syntax">random</span><span class="plain-syntax">(</span><span class="identifier-syntax">best_count</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">len</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> = </span><span class="identifier-syntax">LIST_OF_TY_GetItem</span><span class="plain-syntax">(</span><span class="identifier-syntax">director_speaker_list</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> = </span><span class="identifier-syntax">DirectorScoreConverser</span><span class="plain-syntax">(</span><span class="identifier-syntax">speaker</span><span class="plain-syntax">, </span><span class="identifier-syntax">select_speaker</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> == </span><span class="identifier-syntax">best_score</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">x</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">x</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">speaker</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">best</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">x</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">K2_thing</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">x</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">player</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">x</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. Scoring possible speakers. </b>Note that the scoring depends on whether we're looking for a speaker or an
interlocutor, and also on whether the line is verbal or non-verbal.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorScoreConverser</span><span class="plain-syntax"> </span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> </span><span class="identifier-syntax">select_speaker</span><span class="plain-syntax"> </span><span class="identifier-syntax">nonverbal</span><span class="plain-syntax"> </span><span class="identifier-syntax">this_score</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">select_speaker</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">OnStage</span><span class="plain-syntax">(</span><span class="identifier-syntax">speaker</span><span class="plain-syntax">, -1)) </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> = </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> + </span><span class="constant-syntax">16</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">DirectorTestAccessible</span><span class="plain-syntax">(</span><span class="identifier-syntax">player</span><span class="plain-syntax">, </span><span class="identifier-syntax">speaker</span><span class="plain-syntax">, </span><span class="identifier-syntax">nonverbal</span><span class="plain-syntax">)) </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> = </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> + </span><span class="constant-syntax">8</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> == </span><span class="identifier-syntax">DirectorStackLastInterlocutor</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">director_sp</span><span class="plain-syntax">-1)) </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> = </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> + </span><span class="constant-syntax">4</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">K8_person</span><span class="plain-syntax">) </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> = </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> + </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">DirectorStackLastSpeaker</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">director_sp</span><span class="plain-syntax">-1)) </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> = </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">OnStage</span><span class="plain-syntax">(</span><span class="identifier-syntax">speaker</span><span class="plain-syntax">, -1)) </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> = </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> + </span><span class="constant-syntax">16</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">DirectorTestAccessible</span><span class="plain-syntax">(</span><span class="identifier-syntax">player</span><span class="plain-syntax">, </span><span class="identifier-syntax">speaker</span><span class="plain-syntax">, </span><span class="identifier-syntax">nonverbal</span><span class="plain-syntax">)) </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> = </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> + </span><span class="constant-syntax">8</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> == </span><span class="identifier-syntax">DirectorStackLastSpeaker</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">director_sp</span><span class="plain-syntax">-1)) </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> = </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> + </span><span class="constant-syntax">4</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> </span><span class="reserved-syntax">ofclass</span><span class="plain-syntax"> </span><span class="identifier-syntax">K8_person</span><span class="plain-syntax">) </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> = </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> + </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">DirectorStackLastInterlocutor</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">director_sp</span><span class="plain-syntax">-1)) </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> = </span><span class="identifier-syntax">this_score</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">this_score</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorTestAccessible</span><span class="plain-syntax"> </span><span class="identifier-syntax">from</span><span class="plain-syntax"> </span><span class="reserved-syntax">to</span><span class="plain-syntax"> </span><span class="identifier-syntax">nonverbal</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">nonverbal</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TestVisibility</span><span class="plain-syntax">(</span><span class="identifier-syntax">from</span><span class="plain-syntax">, </span><span class="reserved-syntax">to</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TestAudibility</span><span class="plain-syntax">(</span><span class="identifier-syntax">from</span><span class="plain-syntax">, </span><span class="reserved-syntax">to</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. Performing a line. </b>The following attempts to perform a line, though this may by stymied in a variety
of ways. The return value is <span class="extract"><span class="extract-syntax">true</span></span> if a line is actually performed, <span class="extract"><span class="extract-syntax">false</span></span>
otherwise.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorPerformLine</span><span class="plain-syntax"> </span><span class="identifier-syntax">dl</span><span class="plain-syntax"> </span><span class="identifier-syntax">linedata</span><span class="plain-syntax"> </span><span class="identifier-syntax">fn</span><span class="plain-syntax"> </span><span class="identifier-syntax">action_fn</span><span class="plain-syntax"> </span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> </span><span class="identifier-syntax">interlocutor</span><span class="plain-syntax"> </span><span class="identifier-syntax">mentioning</span><span class="plain-syntax"> </span><span class="identifier-syntax">nonverbal</span><span class="plain-syntax"> </span><span class="identifier-syntax">ta</span><span class="plain-syntax"> </span><span class="identifier-syntax">rv</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">dl</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">dl</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">NO_DIALOGUE_LINES</span><span class="plain-syntax">)) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="comment-syntax">Must either be unperformed or recurring</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">DIALOGUE_LINE_TY</span><span class="plain-syntax">, </span><span class="identifier-syntax">dl</span><span class="plain-syntax">, </span><span class="identifier-syntax">performed</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">GProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">DIALOGUE_LINE_TY</span><span class="plain-syntax">, </span><span class="identifier-syntax">dl</span><span class="plain-syntax">, </span><span class="identifier-syntax">recurring</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">)) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">linedata</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableOfDialogueLines</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">dl</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="comment-syntax">Must be available</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">fn</span><span class="plain-syntax"> = </span><span class="identifier-syntax">linedata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">AVAILABILITY_DLMETADATA</span><span class="plain-syntax">; </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">fn</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">fn</span><span class="plain-syntax">() == </span><span class="reserved-syntax">false</span><span class="plain-syntax">)) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">linedata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">FLAGS_DLMETADATA</span><span class="plain-syntax">) &amp; </span><span class="identifier-syntax">NONVERBAL_FLAG_DLMETADATA</span><span class="plain-syntax">) </span><span class="identifier-syntax">nonverbal</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="comment-syntax">An accessible speaker matching the description must be found, if a description is given</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">linedata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">SPEAKER_DLMETADATA</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> = </span><span class="identifier-syntax">DirectorSelectConverser</span><span class="plain-syntax">(</span><span class="identifier-syntax">linedata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">SPEAKER_DLMETADATA</span><span class="plain-syntax">, </span><span class="reserved-syntax">true</span><span class="plain-syntax">, </span><span class="identifier-syntax">nonverbal</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> == </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">DirectorTestAccessible</span><span class="plain-syntax">(</span><span class="identifier-syntax">player</span><span class="plain-syntax">, </span><span class="identifier-syntax">speaker</span><span class="plain-syntax">, </span><span class="identifier-syntax">nonverbal</span><span class="plain-syntax">) == </span><span class="reserved-syntax">false</span><span class="plain-syntax">)) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="comment-syntax">An accessible interlocutor matching the description must be found, if a description is given</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">linedata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">INTERLOCUTOR_DLMETADATA</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">interlocutor</span><span class="plain-syntax"> = </span><span class="identifier-syntax">DirectorSelectConverser</span><span class="plain-syntax">(</span><span class="identifier-syntax">linedata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">INTERLOCUTOR_DLMETADATA</span><span class="plain-syntax">, </span><span class="reserved-syntax">false</span><span class="plain-syntax">, </span><span class="identifier-syntax">nonverbal</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">interlocutor</span><span class="plain-syntax"> == </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">DirectorTestAccessible</span><span class="plain-syntax">(</span><span class="identifier-syntax">speaker</span><span class="plain-syntax">, </span><span class="identifier-syntax">interlocutor</span><span class="plain-syntax">, </span><span class="identifier-syntax">nonverbal</span><span class="plain-syntax">) == </span><span class="reserved-syntax">false</span><span class="plain-syntax">)) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">action_fn</span><span class="plain-syntax"> = </span><span class="identifier-syntax">linedata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">ACTIONS_DLMETADATA</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="comment-syntax">If the line is "after ..." some action, that action must succeed</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">action_fn</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">ta</span><span class="plain-syntax"> = </span><span class="identifier-syntax">trace_actions</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">debug_dialogue</span><span class="plain-syntax">) </span><span class="identifier-syntax">trace_actions</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">rv</span><span class="plain-syntax"> = </span><span class="identifier-syntax">action_fn</span><span class="plain-syntax">(3, </span><span class="identifier-syntax">speaker</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">trace_actions</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ta</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rv</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">DirectorStackLastSpeaker</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">director_sp</span><span class="plain-syntax">-1) = </span><span class="identifier-syntax">speaker</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DirectorStackLastInterlocutor</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">director_sp</span><span class="plain-syntax">-1) = </span><span class="identifier-syntax">interlocutor</span><span class="plain-syntax">;</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">DivideParagraphPoint</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">DirectorPerformingActivity</span><span class="plain-syntax">(</span><span class="identifier-syntax">dl</span><span class="plain-syntax">, </span><span class="identifier-syntax">speaker</span><span class="plain-syntax">, </span><span class="identifier-syntax">interlocutor</span><span class="plain-syntax">, </span><span class="identifier-syntax">linedata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">STYLE_DLMETADATA</span><span class="plain-syntax">) == </span><span class="reserved-syntax">false</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DivideParagraphPoint</span><span class="plain-syntax">();</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">WriteGProperty</span><span class="plain-syntax">(</span><span class="identifier-syntax">DIALOGUE_LINE_TY</span><span class="plain-syntax">, </span><span class="identifier-syntax">dl</span><span class="plain-syntax">, </span><span class="identifier-syntax">performed</span><span class="plain-syntax">, </span><span class="reserved-syntax">true</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">action_fn</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">ta</span><span class="plain-syntax"> = </span><span class="identifier-syntax">trace_actions</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">debug_dialogue</span><span class="plain-syntax">) </span><span class="identifier-syntax">trace_actions</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="comment-syntax">Carry out any "now" state changes</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">action_fn</span><span class="plain-syntax">(2, </span><span class="identifier-syntax">speaker</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="comment-syntax">Run any "before ..." actions</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">action_fn</span><span class="plain-syntax">(1, </span><span class="identifier-syntax">speaker</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">trace_actions</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ta</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="comment-syntax">Make any newly mentioned subjects live</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">mentioning</span><span class="plain-syntax"> = </span><span class="identifier-syntax">linedata</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">MENTIONING_DLMETADATA</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="reserved-syntax">metaclass</span><span class="plain-syntax">(</span><span class="identifier-syntax">mentioning</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Object</span><span class="plain-syntax">: </span><span class="identifier-syntax">DirectorAddLiveSubjectList</span><span class="plain-syntax">(</span><span class="identifier-syntax">mentioning</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Routine</span><span class="plain-syntax">: </span><span class="identifier-syntax">mentioning</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. Running the performing activity. </b>The only tricky thing here is that we need to expose our data here so that the
activity variables for <span class="extract"><span class="extract-syntax">performing something</span></span> can be initialised. We do that
in a fairly clumsy way, but it's good enough.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">director_current_speaker</span><span class="plain-syntax">;</span>
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">director_current_interlocutor</span><span class="plain-syntax">;</span>
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">director_current_style</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorCurrentLineSpeaker</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">director_current_speaker</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorCurrentLineInterlocutor</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">director_current_interlocutor</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorCurrentLineStyle</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">director_current_style</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">DirectorPerformingActivity</span><span class="plain-syntax"> </span><span class="identifier-syntax">dl</span><span class="plain-syntax"> </span><span class="identifier-syntax">speaker</span><span class="plain-syntax"> </span><span class="identifier-syntax">interlocutor</span><span class="plain-syntax"> </span><span class="identifier-syntax">manner</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">director_current_speaker</span><span class="plain-syntax"> = </span><span class="identifier-syntax">speaker</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">director_current_interlocutor</span><span class="plain-syntax"> = </span><span class="identifier-syntax">interlocutor</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">director_current_style</span><span class="plain-syntax"> = </span><span class="identifier-syntax">manner</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">PERFORMING_DIALOGUE</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="string-syntax">"*** no activity ***"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">BeginActivity</span><span class="plain-syntax">(</span><span class="identifier-syntax">PERFORMING_DIALOGUE</span><span class="plain-syntax">, </span><span class="identifier-syntax">dl</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">ForActivity</span><span class="plain-syntax">(</span><span class="identifier-syntax">PERFORMING_DIALOGUE</span><span class="plain-syntax">, </span><span class="identifier-syntax">dl</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">RulebookFailed</span><span class="plain-syntax">())) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EndActivity</span><span class="plain-syntax">(</span><span class="identifier-syntax">PERFORMING_DIALOGUE</span><span class="plain-syntax">, </span><span class="identifier-syntax">dl</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">director_current_speaker</span><span class="plain-syntax"> = </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">director_current_interlocutor</span><span class="plain-syntax"> = </span><span class="reserved-syntax">nothing</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">director_current_style</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="S-bts.html">&#10094;</a></li><li class="progresssection"><a href="S-drc.html">drc</a></li><li class="progresssection"><a href="S-bts.html">bts</a></li><li class="progresscurrent">lns</li><li class="progresssection"><a href="S-chc.html">chc</a></li><li class="progresssection"><a href="S-prg.html">prg</a></li><li class="progressnext"><a href="S-chc.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

